<?php
header('Access-Control-Allow-Origin:*');
header('Content-Type: text/html; charset=UTF-8');
if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest')) {
  $responseData['status'] = 'error';
  require_once('mysqli.php');
  extract($db->escape_array($_POST));
  if (isset($_GET['get_data'])) {
    //PHP获取$_GET请求参数
    $empno=$_GET['empno'];
    $ename=$_GET['ename'];
    $responseData['empno'] = $empno;
    $responseData['ename'] = $ename;
    $SQL="SELECT * FROM emp WHERE empno={$empno} AND ename={$ename}";
    $responseData['SQL'] = $SQL;
  $rs = $db->get_all("SELECT * FROM emp WHERE empno='{$empno}' AND ename='{$ename}'");
    if ($rs) {
      $responseData['getData'] = array();
      foreach ($rs as $row) {
        $responseData['getData'][] = $row;
      }
      $responseData['success'] = true;
      $responseData['status'] = 'success';
    } elseif ($rs === FALSE) {
      $responseData['errMsg'] = '获取数据时发生SQL错误。';
      $responseData['errCode'] = $db->errno();
      $responseData['errDesc'] = $db->error();
      $responseData['SQL'] = $db->SQL;
    } else {
      $responseData['getData'] = array();

      $responseData['success'] = true;
      $responseData['status'] = 'success';
    }
    exit(json_encode($responseData));
  }
  
  if (isset($_GET['post_data'])) {
    //PHP获得POST参数
    // $responseData['HTTP_RAW_POST_DATA'] = $GLOBALS["HTTP_RAW_POST_DATA"];

    // $rws_post = $GLOBALS["HTTP_RAW_POST_DATA"];
    // $mypost = json_decode($rws_post);
    // $empno=(string)$mypost->empno;
    // $ename=(string)$mypost->ename;
    // $responseData['_POST'] = $_POST;
    $rs = $db->get_all("SELECT * FROM emp");
    if ($rs) {
      $responseData['getData'] = array();
      foreach ($rs as $row) {
        $responseData['getData'][] = $row;
      }
      $responseData['success'] = true;
      $responseData['status'] = 'success';
    } elseif ($rs === FALSE) {
      $responseData['errMsg'] = '获取数据时发生SQL错误。';
      $responseData['errCode'] = $db->errno();
      $responseData['errDesc'] = $db->error();
      $responseData['SQL'] = $db->SQL;
    } else {
      $responseData['getData'] = array();

      $responseData['success'] = true;
      $responseData['status'] = 'success';
    }
    exit(json_encode($responseData));
  }
  $responseData['errMsg'] = '调用参数错误。';
  exit(json_encode($responseData));
}
?>